﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Windows.Forms;

namespace pistolety3
{
    class firebird
    {
        string role = "";
        public string Role
        {
            get { return role; }
            set { this.role = value; }
        }
        string charset = "WIN1250";
        string serwer = "jama.kan.pl";
        string baza = "/usr/interbase/data/zamowienia2.gdb";

        public string getRole(string user)
        {
            string conStr = @"DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=Rsbp-I.i;DBNAME=" + serwer + ":" + baza + ";Charset=" + charset + ";ROLE=" + Role;
            OdbcConnection con = new OdbcConnection(conStr);
            string query = "SELECT a.RDB$RELATION_NAME FROM RDB$USER_PRIVILEGES a where a.RDB$USER='" + user.ToUpper() + "'";
            con.Open();
            OdbcCommand com = new OdbcCommand(query, con);
            OdbcDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                role += dr[0].ToString().TrimStart().TrimEnd() + ";";
            }
            string[] tab = Role.Split(';');

            foreach (string x in tab)
            {
                if (x == "KASJER")
                    role = "KASJER";
                if (x == "ADM")
                    role = "ADM";
            }
            con.Close();
            return Role;
        }

    }
}
